﻿<?php    
   // $name='ad_'.date('Y-m-d_h-m-s')
    //;
      
    $date = getdate();
    $strdate = $date['year'].'-'.$date['mon'].'-'.$date['mday'].'_'.
                $date['hours'].'-'.$date['minutes'].'-'.$date['seconds'];
    $fmtdate = $date['mday'].'/'.$date['mon'].'/'.$date['year'].' '.
                $date['hours'].':'.$date['minutes'].':'.$date['seconds'];
                
    //so dau la mscb- time-phieudt(xuat phieu_dt,ketqua)
    $name='p'.$cb['User']['canbo_id'].'_'.$strdate;//date('Y-m-d_h-m-s');
  
    ini_set('memory_limit','512M');
    $worksheets = '';
    
    // Sheet đầu tiên lưu thông tin của cán bộ
    $rows = $xls->row($xls->hcell('UID').$xls->hcell('CBID').$xls->hcell('Họ tên').$xls->hcell('Thời điểm tải về'));
    $rows .= $xls->row($xls->cell($cb['User']['id']).$xls->cell($cb['User']['canbo_id']).$xls->cell($cb['Canbo']['HOTEN']).$xls->cell($fmtdate));
    $worksheets .= $xls->worksheet('ThongTin', $rows);    
   
    
    // bang phieu_dts
    $rows = $xls->row($xls->hcell('id').$xls->hcell('sotay_id').
                            $xls->hcell('canbo_id').$xls->hcell('NGAY').
                            $xls->hcell('nss_id').$xls->hcell('LAN').
                            $xls->hcell('date_sua'));
    foreach ( $phieudts as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['phieu_dts']['id']);
        $cells .= $xls->Cell($result['phieu_dts']['sotay_id']);
        $cells .= $xls->Cell($result['phieu_dts']['canbo_id']);
        $cells .= $xls->Cell($result['phieu_dts']['NGAY']);
        $cells .= $xls->Cell($result['phieu_dts']['nss_id']);
        $cells .= $xls->Cell($result['phieu_dts']['LAN']);
        $cells .= $xls->Cell($result['phieu_dts']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('phieudts',$rows);
        
    
    
    $rows = $xls->row($xls->hcell('id').$xls->hcell('doituong_id').
                            $xls->hcell('phieu_dt_id').$xls->hcell('nd_dt_id').
                            $xls->hcell('diem_dt_id').$xls->hcell('KETQUA').
                            $xls->hcell('date_sua'));
            
   
// bang ketquas

    foreach ( $ketquas as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['ketquas']['id']);
        $cells .= $xls->Cell($result['ketquas']['doituong_id']);
        $cells .= $xls->Cell($result['ketquas']['phieu_dt_id']);
        $cells .= $xls->Cell($result['ketquas']['nd_dt_id']);
        $cells .= $xls->Cell($result['ketquas']['diem_dt_id']);
        $cells .= $xls->Cell($result['ketquas']['KETQUA']);
        $cells .= $xls->Cell($result['ketquas']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('ketquas',$rows);

             
    // If you print the output to the screen set the proper headers
    $xls->setHeader($name);
    
    //Trong truong hop khong muon ma hoa
    echo $xls->workbook($worksheets);
   
   //Trong truong hop muon ma hoa
      
 /*     
    
    $data = $xls->workbook($worksheets); 
    
    $cryptastic = new cryptastic;
    $encData = $cryptastic->encrypt($data, true);
    if($encData === false){
        $session->setFlash('Lỗi mã hóa dữ liệu');
        $this->redirect(array('controller'=>'bks','action'=>'index'));
    }else{
        echo $encData;
    }
   */ 
   
?> 